<?php
	class Auth extends CI_Controller{
		function __Construct(){
			parent ::__Construct();
			$this->load->model("back_models","admin");
			if(!$this->session->userdata['user_data']){
				redirect(BASE_URL."back/login");
			}
		}
	function index(){
				$user_data = $this->session->userdata("user_data");
				$finduser['user_id'] = $user_data['user_id'];
				$user_info = $this->admin->finduser($finduser);
				$data['data']['user_data'] = $user_info;
				$data['data']['template'] = 'user/info';
				$this->load->view("template",$data);
	}
	function info(){
				$user_data = $this->session->userdata("user_data");
				$finduser['user_id'] = $user_data['user_id'];
				$user_info = $this->admin->finduser($finduser);
				$data['data']['user_data'] = $user_info;
				if($this->input->post("update")){
						$fullname = $this->input->post("fullname");
						$email = $this->input->post("email");
						$gt = $this->input->post("gt");
						$birthday = datetoint($this->input->post('birthday'));
						$phone = $this->input->post('phone');
						$fillter = array(
							'user_id' => $user_data['user_id'],
							'fullname' => $fullname,
							'email' => $email,
							'gender' => $gt,
							'birthday' => $birthday,
							'phone' => $phone,
							
						);
						$this->admin->update($user_data['user_id'],$fillter);
						redirect(BASE_URL."back/auth/info","refresh");
				}
				$data['data']['template'] = 'user/info';
				$data['data']['title'] = 'Thông tin chung';
				$this->load->view("template",$data);
			}
	function password(){
				$user_data = $this->session->userdata("user_data");
				$finduser['user_id'] = $user_data['user_id'];
				$user_info = $this->admin->finduser($finduser);
				$data['data']['user_data'] = $user_info;
				if($this->input->post('update')){
					$fillter['password'] = $this->input->post("newpassword");
					$this->admin->update($user_info['user_id'],$fillter);
					redirect(BASE_URL."back/auth/info","refresh");
				}
				$data['data']['template'] = 'user/password';
				$data['data']['title'] = 'Thay đổi mật khẩu';
				$this->load->view("template",$data);
			}
	function create(){
				$user_data = $this->session->userdata("user_data");
				$finduser['user_id'] = $user_data['user_id'];
				$user_info = $this->admin->finduser($finduser);
				$data['data']['user_data'] = $user_info;
				$data['data']['template'] = 'user/create_user';
				$data['data']['title'] = 'Thêm tài khoản mới';
				$this->load->view("template",$data);
	}
}